Sunday, October 29, 2006

Processor Open Source

As I've mentioned, I like designing CPUs in Verilog for FPGAs. I've seen Sun's major release of some of its SPARC products, but always thought they'd be too large for typical FPGAs.

However, I notice the MicroSPARC source is available -- might have some promise. Of course, there are plenty of "amateur" cores at http://www.fpgacpu.org and http://www.opencores.org if you aren't inclined to design your own.

Labels: ,

Submit to:   book mark Processor Open Source in del.icio.usDel.icio.us  |   submit Processor Open Source to digg.comDigg  |   submit Processor Open Source to slashdot.comSlashdot  |  diigo itDiigo

Friday, October 27, 2006

More on my Homebrew CPU

I've mentioned the homebrew CPU on the Spartan 3 board I've been building for the last year. The internal architecture is sort of "old school" -- internally there is a 16-bit bus connecting all the processor resources. Fixed logic handles all the operations (that is, it isn't microcoded).

I call it Spartan Blue because it is very loosely based on "Blue" the CPU used as a learning tool in Caxton Foster's excellent (but dated) Computer Architecture text book. However, Spartan Blue is a lot more advanced than Blue. My version incorporates indexing, a stack, conditional skips, and several other "advanced" features. All instructions complete in one "super cycle" or less (short instructions restart the super cycle; all of the original Blue's instructions finished in one or two super cycles).

I don't know if anyone ever built a real "Blue" machine -- I know the book has a few errors in it. And my design is different enough that it isn't really "Blue" at all. But you have to wonder if anyone ever made a faithful reproduction of Foster's machine.

For the assembler I originally started writing it in awk. However, that proved too limiting so I had it autoconverted into Perl and then continued writing it in Perl. This allows for constant expressions and several other features. I recently "discovered" that Perl has long shipped with perlcc which lets you compile your Perl program to an executable. A shell script calls the C preprocessor before it launches the assembler, so overall it is a pretty powerful system without much work.

Here's part of the monitor software:

call print_msgcr+CODEOFFSET
ds "Blue Monitor 0.4\xFF"
prompt: call print_msg+CODEOFFSET
ds "\r\r\nBLUE> \xFF"
prompt0:
call waitcharecho+CODEOFFSET
JMPIF(lf+CODEOFFSET,prompt0+CODEOFFSET)

More later.

Labels: ,

Submit to:   book mark More on my Homebrew CPU in del.icio.usDel.icio.us  |   submit More on my Homebrew CPU to digg.comDigg  |   submit More on my Homebrew CPU to slashdot.comSlashdot  |  diigo itDiigo

Thursday, October 26, 2006

Relay Computer


Wow! I like to build CPUs, but mine are on an FPGA. Not Harry's:
http://web.cecs.pdx.edu/~harry/Relay/index.html

Labels: , ,

Submit to:   book mark Relay Computer in del.icio.usDel.icio.us  |   submit Relay Computer to digg.comDigg  |   submit Relay Computer to slashdot.comSlashdot  |  diigo itDiigo

Tuesday, October 17, 2006

More on the Spartan 3 Starter Kit Computer

I promised a bit more about the computer I've built around the Spartan 3 Starter Kit. Let me tell you a bit about the front panel. The CPU is a 16-bit machine with a 12-bit address bus (4K words or 8K bytes of memory). But the board doesn't have enough I/O to actually support this via the front panel. So a little ingenuity was required.

The board has 4 numeric digital displays. These can display hex (if you provide a hex decoder in the FPGA) so that's enough to show a single 16-bit quantity. Each digit also has a decimal point which will become important later.

The board also has 8 toggle switches, 8 discrete LEDs, and only 4 push buttons that you can use. Let's start with the 4 buttons. The leftmost button is predefined to the FPGA's reset line, so it is the reset button. The next button selects the mode of the front panel (there are 6 modes that you select sequentially -- each button press picks the next mode). The second to last button is an "execute" button that means different things depending on the current mode. The final button works as an "enter button" in all modes. Of the 8 LEDs, 6 are dedicated to showing the current mode.

Mode 0 - Register select
In this mode, each press of the enter key changes what register the display shows. The display can show 4 different registers and which one it shows is indicated by which decimal point is turned on. When the rightmost decimal point is on, the display shows the program counter (PC). The next LED signifies the accumulator is displayed. The 3rd LED indicates the "switch" register (more on that in a second). The final LED indicates the instruction register (IR) is displayed.

Note that in all modes, when you press the enter key and hold it down, the front panel does three things:
  1. It shifts the switch register left 8 bits
  2. It puts the current 8 switches into the right 8 bits of the switch register
  3. It displays the switch register (and the corresponding decimal point) until you release the button
So to enter A105 into the switch register, you have to enter A1 into the switches, press enter, and then enter 05 into the switches and press enter again.

Mode 1 - Set PC
Pressing execute in this mode transfers the switch register to the program counter.

Mode 2 - Dump
In this mode, every press of the execute button puts the contents of the memory at the PC into the accumulator and increments the program counter. You can use this to examine memory.

Mode 3 - Load
This is similar to mode 2 except that pressing the execute button puts the contents of the switch register into the memory at PC and increments PC. In addition, in this mode (and assuming the processor is halted) any bytes that show up on the serial port will be entered as though they were entered at the switches. This is a handy way to load an initial program over the serial port (sort of like a paper tape reader).

Mode 4 - Single Step
This mode causes the program to step each time you press execute.

Mode 5 - Run
When in mode 5, pressing execute will start the processor running (or stop it if it is running already).

The two leftmost LEDs are used to indicate status. The very leftmost LED is the Q LED which the program can turn on and off (useful for debugging). The next LED turns on when the processor is running.

This is surprisingly flexible and is pretty quick to operate once you get the hang of it. Of course, you don't want to enter long programs which is why there is the serial port option.

The switch register can be read and written under program control. The program can also read the raw value of the switch inputs. These are mapped, along with the UART registers, to the top part of the memory (FF0-FFF are reserved for I/O).

So that gives you a little flavor of what I do in my spare time. Next time I'll talk about the instruction set (which includes a stack, indexing, and a few other interesting instructions).

Labels: , ,

Submit to:   book mark More on the Spartan 3 Starter Kit Computer in del.icio.usDel.icio.us  |   submit More on the Spartan 3 Starter Kit Computer to digg.comDigg  |   submit More on the Spartan 3 Starter Kit Computer to slashdot.comSlashdot  |  diigo itDiigo